<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>企业红头文件模版</title>
    <link rel="stylesheet" href="../css/all.min.css">
    <style>
        :root {
            --primary-color: #c00;
            --secondary-color: #333;
            --light-gray: #f5f7fa;
            --border-color: #e1e5ee;
            --shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s ease;
        }
        
        * {
            box-sizing: border-box;
            transition: var(--transition);
        }
        
        body {
            font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
            margin: 0;
            padding: 20px;
            background-color: var(--light-gray);
            color: var(--secondary-color);
            line-height: 1.6;
            overflow-y: hidden;
        }
        
        .container {
            margin: 0 auto;
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
        }
        
        .preview-section {
            background: white;
            border-radius: 12px;
            padding: 20px;
            overflow-y: auto;
            max-height: calc(100vh - 40px);
        }
        
        .form-section {
            background: white;
            border-radius: 12px;
            box-shadow: var(--shadow);
            padding: 20px;
        }
        
        .section-header {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid var(--border-color);
        }
        
        .section-header i {
            color: var(--primary-color);
            font-size: 24px;
            margin-right: 10px;
        }
        
        .section-header h2 {
            margin: 0;
            color: var(--secondary-color);
            font-size: 20px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #555;
            font-size: 14px;
        }
        
        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            font-size: 14px;
            background-color: white;
        }
        
        .form-control:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(204, 0, 0, 0.2);
            outline: none;
        }
        
        textarea.form-control {
            min-height: 250px;
            resize: vertical;
        }
        
        .document-preview {
            background-color: white;
            padding: 5px;
            position: relative;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1) inset;
        }
        
        .red-header {
            position: relative;
            text-align: center;
            margin-bottom: 60px;
            padding-top: 60px;
        }
        
        .company-name {
            color: var(--primary-color);
            font-size: 42px;
            font-weight: bold;
            letter-spacing: 2px;
            margin-bottom: 15px;
            font-family: "SimHei", "黑体", sans-serif;
            text-shadow: 0 1px 2px rgba(0,0,0,0.1);
        }
        
        .red-line {
            height: 3px;
            background-color: var(--primary-color);
            position: relative;
        }
        
        
        .red-line:before {
            left: 0;
        }
        
        .red-line:after {
            right: 0;
        }
        
        .document-title {
            font-size: 28px;
            font-weight: bold;
            margin: 30px 0;
            color: #222;
        }
        
        .document-number {
            text-align: left;
            margin-bottom: 40px;
            font-size: 18px;
            color: #555;
        }
        
        .document-content {
            font-size: 18px;
            text-indent: 2em;
            color: #333;
        }
        
        .document-footer {
            margin-top: 100px;
            display: flex;
            justify-content: space-between;
            font-size: 18px;
            color: #555;
        }
        
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 12px 20px;
            border-radius: 8px;
            font-weight: 500;
            font-size: 14px;
            cursor: pointer;
            border: none;
            transition: var(--transition);
            color: white;
            margin-bottom: 10px;
            width: 100%;
            text-align: center;
        }
        
        .btn i {
            margin-right: 8px;
            font-size: 14px;
        }
        
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            box-shadow: 0 4px 10px rgba(204, 0, 0, 0.3);
        }
        
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(204, 0, 0, 0.4);
            background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
        }
        
        .btn-secondary {
            background-color: #555;
            box-shadow: 0 4px 10px rgba(85, 85, 85, 0.3);
        }
        
        .btn-secondary:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(85, 85, 85, 0.4);
            background-color: #444;
        }
        
        .tooltip {
            position: relative;
            display: inline-block;
            margin-left: 5px;
            color: #999;
            cursor: help;
        }
        
        .tooltip .tooltiptext {
            visibility: hidden;
            width: 200px;
            background-color: #555;
            color: #fff;
            text-align: center;
            border-radius: 6px;
            padding: 5px;
            position: absolute;
            z-index: 1;
            bottom: 125%;
            left: 50%;
            margin-left: -100px;
            opacity: 0;
            transition: opacity 0.3s;
            font-size: 12px;
            font-weight: normal;
        }
        
        .tooltip:hover .tooltiptext {
            visibility: visible;
            opacity: 1;
        }
        
        @media (max-width: 1200px) {
            .container {
                grid-template-columns: 1fr;
            }
            
            .preview-section {
                position: static;
            }
        }
        
        @media print {
            .form-section {
                display: none !important;
            }
            
            .document-preview {
                padding: 0;
                box-shadow: none;
                min-height: auto;
            }
            
            body {
                background: none;
                padding: 0;
            }
            .fixed-buttons {
                display: none;
            }
        }

        .fixed-buttons {
            position: fixed;
            top: 50%;
            right: 20px;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 表单区 -->
        <div class="form-section">
            <div class="section-header">
                <i class="fas fa-edit"></i>
                <h2>文件信息</h2>
            </div>
            
            <div class="form-group">
                <label for="companyName">
                    公司名称
                    <span class="tooltip">
                        <i class="fas fa-question-circle"></i>
                        <span class="tooltiptext">请输入公司全称，将显示在文件最上方</span>
                    </span>
                </label>
                <input type="text" id="companyName" class="form-control" placeholder="请输入公司全称" value="某某科技有限公司">
            </div>
            
            <div class="form-group">
                <label for="fileTitle">
                    文件标题
                    <span class="tooltip">
                        <i class="fas fa-question-circle"></i>
                        <span class="tooltiptext">如：关于召开年度会议的通知</span>
                    </span>
                </label>
                <input type="text" id="fileTitle" class="form-control" placeholder="请输入文件标题" value="关于召开年度工作会议的通知">
            </div>
            
            <div class="form-group">
                <label for="fileNumber">
                    文件编号
                    <span class="tooltip">
                        <i class="fas fa-question-circle"></i>
                        <span class="tooltiptext">格式示例：XX〔XXXX〕XX号</span>
                    </span>
                </label>
                <input type="text" id="fileNumber" class="form-control" placeholder="请输入文件编号" value="XX〔XXXX〕XX号">
            </div>
            
            <div class="form-group">
                <label for="mainContent">
                    正文内容
                    <span class="tooltip">
                        <i class="fas fa-question-circle"></i>
                        <span class="tooltiptext">支持自动换行，段落间空一行即可</span>
                    </span>
                </label>
                <textarea id="mainContent" class="form-control" placeholder="请输入正文内容">根据公司年度工作安排，经研究决定召开XXXX年度工作会议，现将有关事项通知如下：

一、会议时间：XXXX年XX月XX日（星期X）上午9:00
二、会议地点：公司三楼大会议室
三、参会人员：公司全体中层以上管理人员
四、会议内容：总结XXXX年度工作，部署XX年度工作计划

请各部门负责人做好工作安排，准时参加会议。</textarea>
            </div>
            
            <div class="form-group">
                <label for="date">
                    发布日期
                    <span class="tooltip">
                        <i class="fas fa-question-circle"></i>
                        <span class="tooltiptext">格式示例：XXXX年XX月XX日</span>
                    </span>
                </label>
                <input type="text" id="date" class="form-control" placeholder="请输入发布日期" value="XXXX年XX月XX日">
            </div>
            
            <div id="alertArea"></div>
        </div>

        <div class="preview-section">
            <div id="preview" class="document-preview">
                <div class="red-header">
                    <div class="company-name" id="previewCompanyName">某某科技有限公司</div>
                    <div class="red-line"></div>
                    <div class="document-title" id="previewFileTitle">关于召开年度工作会议的通知</div>
                    <div class="document-number" id="previewFileNumber">XX〔XXXX〕XX号</div>
                </div>
                
                <div class="document-content" id="previewMainContent">
                </div>
                
                <div class="document-footer">
                    <div id="previewDate">XXXX年XX月XX日</div>
                    <div><span id="footerCompanyName">某某科技有限公司</span><br>（此件公开发布）</div>
                </div>
            </div>
        </div>
    </div>

    <div class="fixed-buttons">
        <button class="btn btn-primary" id="generateBtn">
            <i class="fas fa-magic"></i> 生成文件
        </button>
        <button class="btn btn-secondary" id="printBtn" style="display: none;">
            <i class="fas fa-print"></i> 打印文件
        </button>
        <button class="btn btn-secondary" id="resetBtn">
            <i class="fas fa-redo"></i> 重置表单
        </button>
    </div>

    <script>
        // DOM加载完成后执行
        document.addEventListener('DOMContentLoaded', function() {
            // 生成红头文件
            document.getElementById('generateBtn').addEventListener('click', generateDocument);
            
            // 打印功能 - 只打印红头文件
            document.getElementById('printBtn').addEventListener('click', function() {
                // 临时隐藏按钮
                const generateBtn = document.getElementById('generateBtn').style.display;
                document.getElementById('generateBtn').style.display = 'none';
                const printBtn = document.getElementById('printBtn').style.display;
                document.getElementById('printBtn').style.display = 'none';
                const resetBtn = document.getElementById('resetBtn').style.display;
                document.getElementById('resetBtn').style.display = 'none';
                
                // 打印
                window.print();
                
                // 恢复按钮显示
                setTimeout(() => {
                    document.getElementById('generateBtn').style.display = generateBtn;
                    document.getElementById('printBtn').style.display = printBtn;
                    document.getElementById('resetBtn').style.display = resetBtn;
                }, 500);
            });
            
            
            // 重置功能
            document.getElementById('resetBtn').addEventListener('click', resetForm);
            
            // 显示提示信息
            function showAlert(message, type) {
                const alertArea = document.getElementById('alertArea');
                const icon = type === 'success' ? 'fa-check-circle' : 
                             type === 'danger' ? 'fa-exclamation-circle' : 'fa-info-circle';
                const alertClass = type === 'success' ? 'alert-success' : 
                                 type === 'danger' ? 'alert-danger' : 'alert-info';
                
                const alertDiv = document.createElement('div');
                alertDiv.className = `alert ${alertClass}`;
                alertDiv.innerHTML = `<i class="fas ${icon}"></i> ${message}`;
                
                alertArea.insertBefore(alertDiv, alertArea.firstChild);
                
                // 5秒后自动消失
                setTimeout(() => {
                    alertDiv.style.opacity = '0';
                    setTimeout(() => alertDiv.remove(), 300);
                }, 5000);
            }
            
            // 生成文档函数
            function generateDocument() {
                // 获取表单值
                const companyName = document.getElementById('companyName').value;
                const fileTitle = document.getElementById('fileTitle').value;
                const fileNumber = document.getElementById('fileNumber').value;
                const mainContent = document.getElementById('mainContent').value;
                const date = document.getElementById('date').value;
                
                // 验证必填字段
                if (!companyName || !fileTitle || !fileNumber || !mainContent || !date) {
                    showAlert('请填写所有必填字段！', 'danger');
                    return;
                }
                
                // 更新预览
                document.getElementById('previewCompanyName').textContent = companyName;
                document.getElementById('previewFileTitle').textContent = fileTitle;
                document.getElementById('previewFileNumber').textContent = fileNumber;
                
                // 处理正文内容的换行
                const formattedContent = mainContent.replace(/\n/g, '<br>');
                document.getElementById('previewMainContent').innerHTML = formattedContent;
                
                document.getElementById('previewDate').textContent = date;
                // 更新页脚的公司名称
                document.getElementById('footerCompanyName').textContent = companyName;
                
                // 显示操作按钮
                document.getElementById('printBtn').style.display = 'block';
                
                showAlert('文件生成成功！', 'success');
            }
            
            // 重置表单函数
            function resetForm() {
                // 重置表单值
                document.getElementById('companyName').value = '某某科技有限公司';
                document.getElementById('fileTitle').value = '关于召开年度工作会议的通知';
                document.getElementById('fileNumber').value = 'XX〔XXXX〕XX号';
                document.getElementById('mainContent').value = `根据公司年度工作安排，经研究决定召开XXXX年度工作会议，现将有关事项通知如下：

一、会议时间：XXXX年XX月XX日（星期X）上午9:00
二、会议地点：公司三楼大会议室
三、参会人员：公司全体中层以上管理人员
四、会议内容：总结XXXX年度工作，部署XX年度工作计划

请各部门负责人做好工作安排，准时参加会议。`;
                document.getElementById('date').value = 'XXXX年XX月XX日';
                
                // 隐藏操作按钮
                document.getElementById('printBtn').style.display = 'none';
                
                // 重新生成默认文档
                generateDocument();
                
                showAlert('表单已重置为默认值', 'success');
            }
            
            // 初始化默认生成
            generateDocument();
        });
    </script>
</body>
</html>
    